package com.zhanggm.ry.stock.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.zhanggm.ry.stock.entity.Stock;
import com.zhanggm.ry.stock.service.IStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 库存表，代表库存，秒杀库存等信息 前端控制器
 * </p>
 *
 * @author zhanggm
 * @since 2023-04-25
 */
@RestController
@RequestMapping("/stock")
public class StockController {

    @Autowired
    private IStockService stockService;

    @PutMapping("reduce")
    public AjaxResult reduce(@RequestParam("skuId") Long skuId, @RequestParam("stockNum") Integer stockNum) {
        Stock stock = stockService.getById(skuId);
        stock.setStock(stock.getStock() - stockNum);
        stockService.updateById(stock);
        return AjaxResult.success();
    }

}
